#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class CBook {
private:
	string B_name;
	string name;
	double price;
	string press;
public:
	CBook(){}
	void setCBook(string _B_name, string _name, double _price, string _press) {
		B_name = _B_name;
		name = _name;
		price = _price;
		press = _press;
	}
	friend void find(CBook* book, int n, int& max1index, int& max2index) {
		double max = book[0].price;
		max1index = 0;
		for (int i = 1; i < n; i++) {
			if (book[i].price > max) {
				max = book[i].price;
				max1index = i;
			}
		}
		if (max1index == 0) {
			max = book[1].price;
		}
		else {
			max = book[0].price;
		}
		for (int i = 0; i < n; i++) {
			if (i == max1index) {
				continue;
			}
			if (book[i].price > max) {
				max = book[i].price;
				max2index = i;
			}
		}
	}
	void print()
	{
		cout << B_name << endl;
		cout << name << endl;
		cout << fixed << setprecision(2) << price << endl;
		cout << press << endl;
	}
};
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		CBook* book = new CBook[n];
		string B_name;
		string name;
		double price;
		string press;
		char ch;
		for (int j = 0; j < n; j++) {
			getline(cin, B_name, ',');
			getline(cin, name, ',');
			cin >> price >> ch;
			getline(cin, press, '\n');
			book[j].setCBook(B_name, name, price, press);
		}
		int max1, max2;
		find(book, n, max1, max2);
		book[max1].print();
		cout << endl;
		book[max2].print();
	}
	return 0;
}